<article class="cl pd-20">
    <form action="" method="post" class="form form-horizontal" id="form-save">
        <input type="hidden" id="roleid" name="roleid" value="{$data.roleid}">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>角色名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$data.name}" placeholder="" id="name" name="name"
                    datatype="*4-16" nullmsg="角色名称">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">备注：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$data.remark}" placeholder="备注" id="remark" name="remark">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">权限选择：</label>
            <div class="formControls col-xs-8 col-sm-9">
                {foreach $dataPermission as $value}
                <dl class="permission-list">
                    <dt>
                        <label>
                            <input type="checkbox" value="{$value.menuid}" id="check_{$value.menuid}" name="perm_check[]" {if
                                condition="in_array($value.menuid, $rolePowers)" }checked{/if}>
                            {$value.name}</label>
                    </dt>
                    {notempty name='value.child'}
                    {foreach $value.child as $val}
                    <dd>
                        <dl class="cl permission-list2">
                            <dt>
                                <label class="">
                                    <input type="checkbox" value="{$val.menuid}" name="perm_check[]" id="check_{$val.menuid}"
                                        {if condition="in_array($val.menuid, $rolePowers)" }checked{/if}>
                                    {$val.name}</label>
                            </dt>
                            {notempty name='val.child'}
                            <dd>
                                {foreach $val.child as $vo}
                                <label class="">
                                    <input type="checkbox" value="{$vo.menuid}" name="perm_check[]" id="check_{$val.menuid}" {if
                                        condition="in_array($vo.menuid, $rolePowers)" }checked{/if}>
                                    {$vo.name}</label>
                                {/foreach}
                            </dd>
                            {/notempty}
                        </dl>
                    </dd>
                    {/foreach}
                    {/notempty}
                </dl>
                {/foreach}
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="button" class="btn btn-success radius" id="form-save-button"><i class="icon-ok"></i>
                    确定</button>
                <button type="button" class="btn btn-default radius" onClick="layer_close();"><i
                        class="Hui-iconfont">&#xe66b;</i>取消</button>
            </div>
        </div>
    </form>
</article>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $(function () {
        $(".permission-list dt input:checkbox").click(function () {
            $(this).closest("dl").find("dd input:checkbox").prop("checked", $(this).prop("checked"));
        });
        $(".permission-list2 dd input:checkbox").click(function () {
            var l = $(this).parent().parent().find("input:checked").length;
            var l2 = $(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
            if ($(this).prop("checked")) {
                $(this).closest("dl").find("dt input:checkbox").prop("checked", true);
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", true);
            }
            else {
                if (l == 0) {
                    $(this).closest("dl").find("dt input:checkbox").prop("checked", false);
                }
                if (l2 == 0) {
                    $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", false);
                }
            }
        });

        $("#form-save-button").click(function () {
            var data = $("#form-save").serializeArray();
            $.ajax({
                type: 'POST',
                url: '{:url("save")}',
                data: data,
                dataType: 'json',
                success: function (res) {
                    console.log(res);
                    if (res.code == 0) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            parent.location.reload(); // 父页面刷新
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(res.msg, {
                            icon: 5,
                            time: 1000
                        });
                        return false;
                    }
                }
            })
        });
    })
</script>
<!--请在上方写此页面业务相关的脚本-->